// pages/grow/grow.js

var app = getApp()
var util = require("../../utils/util.js");
Page({

  /**
   * 页面的初始数据
   */
  data: { 
    // isContent: true  
    current: '0',
    isFull: true,
    isFull1: true,
    isFull2: true,
    isFull3: true,
    isFull4: true,
    hidden: true,
    hidden1: true,
    hidden2: true,
    hidden3: true,
    hidden4: true,
    isImg: false,
    img: '../../images/none.png',
    quiet: '../../images/quiet.png',
    moment: '../../images/moment.png',
    arrows: '../../images/arrows.png',
    indicatorDots: true,
    autoplay: false,
    interval: 5000,
    duration: 1000,
    Project1: [
         '测试时间',
         '800米',
        '一分钟跳绳',
        '立定跳远'
    ],
    Project2:[
      '测试时间',
        '30s单摇',
        '30s双摇', 
        '1min棉绳',
        '3min单摇' 
    ],
    Project3: [
        '测试时间',
        '25米',
        '200米'
    ],
    Project4:[
        // '测试时间',
       
    ],
    Project5:[
        '测试时间',
        '800/1000米',
        '50米', 
        '立定跳远', 
        '一分钟仰卧起坐/引体向上'
    ],
    //存放测试成绩
    Test1: [],
    Test2: [],
    Test3: [],
    Test4: [],
    Test5: [],
    //存放精彩瞬间
    splendidMoment1: [],
    splendidMoment2: [],
    splendidMoment3: [],
    splendidMoment4: [],
    splendidMoment5: [],
    //存放成长折线图
    lineChart1: '',
    lineChart2: '',
    lineChart3: '',
    lineChart4: '',
    lineChart5: '',
  },
  bindChange: function(e) {
    // console.log(e)
    var currentTab = e.detail.current;
    this.setData({
      current: currentTab,
    });
  },
  handleChange: function(e) {
    var currentTab = e.detail.key;
    console.log(currentTab)
    this.setData({
      current: currentTab,
    });
  },
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var me = this;
    //判断是否绑定了孩子
    wx.getStorage({
      key: 'childcode',
      success: function (res) {
        console.log('拿到缓存中的childcode')
        console.log(res.data)
        var childcode = res.data;
        if (childcode == '' || childcode == null || childcode == undefined) {
          wx.redirectTo({
            url: '/pages/kid/kid',
          })
        } else {
          //获取数据
          
          var serverUrl = app.serverUrl;
          var Text1 = [];
          var Text2 = [];
          var Text3 = [];
          var Text4 = [];
          var Text5 = [];
          var text1 = [];
          var text2 = [];
          var text3 = [];
          var text4 = [];
          var text5 = [];
          //存放精彩瞬间
          var splendidMoment1 = [];
          var splendidMoment2 = [];
          var splendidMoment3 = [];
          var splendidMoment4 = [];
          var splendidMoment5 = [];
          //存放成长折线图
          var lineChart1 = '';
          var lineChart2 = '';
          var lineChart3 = '';
          var lineChart4 = '';
          var lineChart5 = '';
          wx.request({
            url: serverUrl + '/getGrowProcess',
            data: {
              childcode: childcode,
            },
            header: {
              'content-type': 'application/x-www-form-urlencoded' // 默认值
            },
            method: "POST",
            success: function (res) {
              console.log(res.data)
              console.log(res.data.data)
              //获取每一门课程的成长历程
              var physicFitnessInfo = res.data.data.physicFitness;
              var jumpRopeInfo = res.data.data.jumpRope;
              var swimInfo = res.data.data.swim;
              var midTextInfo = res.data.data.midText;
              var badmintonInfo = res.data.data.badminton;

              //体适能变量定义
              var physicTextTimeList = [];
              var physicRun800mList = [];
              var physicRope1minList = [];
              var physicStandingJumpList = [];
              var physicSplendidMomentList = [];
              var physicLineChart = '';

              //体适能成长历程
              for (var i = 0; i < physicFitnessInfo.length; i++) {
                //测试时间,进行
                physicTextTimeList[i] = physicFitnessInfo[i].date;
                physicTextTimeList[i] = new Date(physicTextTimeList[i]);
                physicTextTimeList[i] = util.formatTime(physicTextTimeList[i]);

                //800m成绩
                physicRun800mList[i] = physicFitnessInfo[i].run800m;
                //一分钟跳绳
                physicRope1minList[i] = physicFitnessInfo[i].rope1min;
                //立定跳远
                physicStandingJumpList[i] = physicFitnessInfo[i].standingjump;
                //体适能精彩瞬间
                physicSplendidMomentList[i] = physicFitnessInfo[i].splendidmoment;
                //体适能成长折线图
                physicLineChart = physicFitnessInfo[i].linechart;

                //存入体适能测试成绩
                text1 = [{
                  time: physicTextTimeList[i],
                  item1: physicRun800mList[i],
                  item2: physicRope1minList[i],
                  item3: physicStandingJumpList[i],
                }]
                Text1 = Text1.concat(text1);
                
                splendidMoment1[i] = serverUrl + physicSplendidMomentList[i];
              }
              //去除空元素
              splendidMoment1 = me.removeEmptyArrayEle(splendidMoment1);
              //成长折线图为空时，赋值为null;
              if (physicLineChart == null || physicLineChart == ''){
                lineChart1 = "";
              }else{
                lineChart1 = serverUrl + physicLineChart;
              }
              //花式跳绳变量定义
              var jumpRopeTextTimeList = [];
              var jumpRopeSingle30sList = [];
              var jumpRopeDouble30sList = [];
              var jumpRopeRope1minList = [];
              var jumpRopeRope3minList = [];
              var jumpRopeSplendidMomentList = [];
              var jumpRopeLineChart = '';

              //花式跳绳成长历程
              for (var i = 0; i < jumpRopeInfo.length; i++) {
                //测试时间,进行
                jumpRopeTextTimeList[i] = jumpRopeInfo[i].date;
                jumpRopeTextTimeList[i] = new Date(jumpRopeTextTimeList[i]);
                jumpRopeTextTimeList[i] = util.formatTime(jumpRopeTextTimeList[i]);

                //30s单摇成绩
                jumpRopeSingle30sList[i] = jumpRopeInfo[i].single30s;
                //30s双摇成绩
                jumpRopeDouble30sList[i] = jumpRopeInfo[i].double30s;
                //一分钟跳绳
                jumpRopeRope1minList[i] = jumpRopeInfo[i].rope1min;
                //三分钟跳绳
                jumpRopeRope3minList[i] = jumpRopeInfo[i].rope3min;
                //花式跳绳精彩瞬间
                jumpRopeSplendidMomentList[i] = jumpRopeInfo[i].splendidmoment;
                //花式跳绳成长折线图
                jumpRopeLineChart = jumpRopeInfo[i].linechart;

                //存入花式跳绳测试成绩
                text2 = [{
                  time: jumpRopeTextTimeList[i],
                  item1: jumpRopeDouble30sList[i],
                  item2: jumpRopeSingle30sList[i],
                  item3: jumpRopeRope1minList[i],
                  item4: jumpRopeRope3minList[i],
                }]
                Text2 = Text2.concat(text2);

                splendidMoment2[i] = serverUrl + jumpRopeSplendidMomentList[i];
              
              }
              splendidMoment2 = me.removeEmptyArrayEle(splendidMoment2);
              if (jumpRopeLineChart == null || jumpRopeLineChart == '') {
                lineChart2 = "";
              } else {
                lineChart2 = serverUrl + jumpRopeLineChart;
              }

              //游泳变量定义
              var swimTextTimeList = [];
              var swim25mList = [];
              var swim200mList = [];
              var swimSplendidMomentList = [];
              var swimLineChart = '';

              //游泳成长历程
              for (var i = 0; i < swimInfo.length; i++) {
                //测试时间,进行
                swimTextTimeList[i] = swimInfo[i].date;
                swimTextTimeList[i] = new Date(swimTextTimeList[i]);
                swimTextTimeList[i] = util.formatTime(swimTextTimeList[i]);

                //游泳25m成绩
                swim25mList[i] = swimInfo[i].swim25m;
                //游泳200m成绩
                swim200mList[i] = swimInfo[i].swim200m;
                //游泳精彩瞬间
                swimSplendidMomentList[i] = swimInfo[i].splendidmoment;
                //游泳成长折线图
                swimLineChart = swimInfo[i].linechart;

                //存入游泳测试成绩
                text3 = [{
                  time: swimTextTimeList[i],
                  item1: swim25mList[i],
                  item2: swim200mList[i],
                }]
                Text3 = Text3.concat(text3);

                splendidMoment3[i] = serverUrl + swimSplendidMomentList[i];
      
              }
              splendidMoment3 = me.removeEmptyArrayEle(splendidMoment3);
              if (swimLineChart == null || swimLineChart == '') {
                lineChart3 = "";
              } else {
                lineChart3 = serverUrl + swimLineChart;
              }

              //羽毛球变量定义
              var badmintonTextTimeList = [];
              var badmintonSplendidMomentList = [];
              var badmintonLineChart = '';

              //羽毛球成长历程
              for (var i = 0; i < badmintonInfo.length; i++) {
                //测试时间
                badmintonTextTimeList[i] = badmintonInfo[i].date;
                badmintonTextTimeList[i] = new Date(badmintonTextTimeList[i]);
                badmintonTextTimeList[i] = util.formatTime(badmintonTextTimeList[i]);

                //羽毛球精彩瞬间
                badmintonSplendidMomentList[i] = badmintonInfo[i].splendidmoment;
                //羽毛球成长折线图
                badmintonLineChart = badmintonInfo[i].linechart;

                //存入羽毛球测试成绩
                text4 = [{
                  time: badmintonTextTimeList[i],
                }]
                Text4 = Text4.concat(text4);

                splendidMoment4[i] = serverUrl + badmintonSplendidMomentList[i];
       
              }
              splendidMoment4 = me.removeEmptyArrayEle(splendidMoment4);
              if (badmintonLineChart == null || badmintonLineChart == '') {
                lineChart4 = "";
              } else {
                lineChart4 = serverUrl + badmintonLineChart;
              }

              //中考体育变量定义
              var midTextTextTimeList = [];
              var midTextRun800mOR1000mList = [];
              var midTextRun50mList = [];
              var midTextStandingJumpList = [];
              var midTextSitupOrPullupList = [];
              var midTextSplendidMomentList = [];
              var midTextLineChart = '';

              //中考体育成长历程
              for (var i = 0; i < midTextInfo.length; i++) {
                //测试时间,进行
                midTextTextTimeList[i] = midTextInfo[i].date;
                midTextTextTimeList[i] = new Date(midTextTextTimeList[i]);
                midTextTextTimeList[i] = util.formatTime(midTextTextTimeList[i]);

                //800m/1000m成绩
                midTextRun800mOR1000mList[i] = midTextInfo[i].run800mor1000m;
                //50m成绩
                midTextRun50mList[i] = midTextInfo[i].run50m;
                //立定跳远  
                midTextStandingJumpList[i] = midTextInfo[i].standingjump;
                //仰卧起坐/引体向上成绩
                midTextSitupOrPullupList[i] = midTextInfo[i].situporpullup;
                //中考体育精彩瞬间
                midTextSplendidMomentList[i] = midTextInfo[i].splendidmoment;
                //中考体育成长折线图
                midTextLineChart = midTextInfo[i].linechart;

                //存入中考体育测试成绩
                text5 = [{
                  time: midTextTextTimeList[i],
                  item1: midTextRun800mOR1000mList[i],
                  item2: midTextRun50mList[i],
                  item3: midTextStandingJumpList[i],
                  item4: midTextSitupOrPullupList[i]
                }]
                Text5 = Text5.concat(text5);

                splendidMoment5[i] = serverUrl + midTextSplendidMomentList[i];
               
              }
              splendidMoment5 = me.removeEmptyArrayEle(splendidMoment5);
              if (midTextLineChart == null || midTextLineChart == '') {
                lineChart5 = "";
              } else {
                lineChart5 = serverUrl + midTextLineChart;
              }

              me.setData({
                Test1: Text1,
                Test2: Text2,
                Test3: Text3,
                Test4: Text4,
                Test5: Text5,
                splendidMoment1: splendidMoment1,
                splendidMoment2: splendidMoment2,
                splendidMoment3: splendidMoment3,
                splendidMoment4: splendidMoment4,
                splendidMoment5: splendidMoment5,
                lineChart1: lineChart1,
                lineChart2: lineChart2,
                lineChart3: lineChart3,
                lineChart4: lineChart4,
                lineChart5: lineChart5,
              })
            },

          })
        }
      }
    })  
   
    
  },
  /**
     * 移除数组中的空元素
     */
  removeEmptyArrayEle: function (arr) {
    for (var i = 0; i < arr.length; i++) {
      if (arr[i] == app.serverUrl || arr[i] == app.serverUrl+'null'
        || arr[i] == app.serverUrl + ' ') {
        arr.splice(i, 1);
        i = i - 1;
      }
    }
    return arr;
  },
 
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})